< previous page page_190 next page >

Page 190
routine to fill two arrays with the pixel values of the foreground and background images. It then examines the foreground pixels. When it finds a magenta pixel, it replaces the foreground pixel value with the background pixel value. When it finds any other pixel value, the program leaves the pixel unchanged. After it has examined all the pixels, the program uses the SetBitmapPixels subroutine to build the result picture directly.
Program Compose2 uses this technique to compose two images much as program Compose does. Program Compose2 is a tiny bit faster and does not require the mask picture for intermediate processing.
There are several techniques you can use to make composite images more realistic. First, place objects in the foreground image both in front of and behind objects in the background image. Doing so increases the appearance of depth and makes the foreground objects seem more integrated into the result.
Another technique uses the fact that the edges of adjacent objects in an image tend to blur together slightly. Blurring the edges of the foreground and background objects slightly makes the foreground objects seem less like you cut them out of a magazine.
Example program Compose3 demonstrates this technique. This program is similar to program Compose2. It examines each pixel to see which are transparent. When it finds a nontransparent pixel, Compose3 examines the adjacent pixels to see which are transparent.
The program then gives the result pixel a color that is a weighted average of the foreground and background pixels' colors. For example, if one-third of the nearby pixels are transparent, the program makes the result pixel one-third of the foreground pixel's value plus two-thirds of the background pixel's value. This program takes longer than the previous programs, but it produces a better result.
A conceptually similar technique produces the composite image at a large scale. It then uses image reduction techniques to shrink the image smoothly. For example, the program could save the results into a file and then use the LoadImage API function described earlier in this chapter to shrink the image. The anti-aliasing effects of LoadImage tend to blur adjacent pixels and remove rough edges from the foreground picture. This technique takes considerably longer than the previous methods because it makes the program work with a much bigger image. For example, if the initial images are twice as tall and wide as the desired final result, the images contain four times as many pixels. Examining all of those pixels may take a while.
Summary
A point process modifies the pixels in an image one at a time. Because only a single pixel is involved in each calculation, most point operations are conceptually very simple. Despite their simplicity, point processes often produce striking results. By adjusting the brightness, color balance, and contrast of an image, you can bring out the best in an otherwise mediocre picture.

 
< previous page page_190 next page >